<?php
error_reporting(E_ALL);
class Catagory extends Controller {
	public function __construct() {
		parent::__construct();
		$this->load->model("catagory_model","catagory");
	}

	public function index() {
		$this->show();
		//$this->show_create();
	}
	
	public function show_create() {
		//$catagory_edit = array_merge($catagory_create,array('act'=>'edit','action'=>'http://'.site_url('catagory/edit')));
		$this->load->view("catagory_form",$data);
	}

	public function show_edit() {
		$this->load->view("catagory_form",$data);
	}

	private function process() {
		$catagory_name = $this->input->post("catagory-name");	//分类名称
		return array("catagory_name"=>$catagory_name);
	}

	/**
	 * 创建分类
	 */
	public function create() {
		$data = $this->process();
		$this->catagory->create($data);
	}

	public function edit() {
		$data = $this->process();
		$this->catagory->updated($data);
	}

	public function del() {
		$data = $this->process();
		$this->catagory->del($data);
	}
	
	/**
	 * 展示某分类下图书列表
	 * 1 - 分类名转为id
	 * 2 - id传给 ebook 模型
	 */
	public function show($catagory = '') {
		//$this->catagory->show();	//显示分类列表
		$id = $this->catagory->getIdByCatagory($catagory);
		$this->load->model("ebook_model","ebook");
		$this->ebook->show($id);
	}
	
	/**
	 * 后台管理页面
	 */
	public function admin() {
		$catagorys = $this->catagory->admin();
		$data['data'] = $catagorys;
		$this->load->view("admin",$data);
	}
}
?>